# coding=utf-8

# import pandas as pd
#
#
# data_line = pd.read_csv(r"D:\file\Python\data.csv")
#
# res = data_line.iloc(0)[0][3]
#
# print(res)


# import csv
# import codecs
#
#
# with codecs.open(r"D:\file\Python\data_nlp.csv", "w", "utf-8-sig") as file:
#     writer = csv.writer(file)
#     # data = ["关键词", "时间", "博主", "内容", "点赞", "转发", "评论"]
#     # [d.encode("utf-8") for d in data]
#     writer.writerow(["关键词", "时间", "博主", "内容", "点赞", "转发", "评论"])
#
#     writer.writerow(["jack", "290", '23r3', '2332', "234", "32", "32"])
#
#


# import datetime
#
#
# def process_date(date_str):
#     # 将日期字符串转换为datetime对象
#     date_obj = datetime.datetime.strptime(date_str, "%Y年%m月%d日 %H:%M")
#
#     # 提取日期部分，忽略时间部分
#     date = date_obj.date()
#
#     # 返回日期对象
#     return date
#
#
# # 示例用法
# date_str = "2020年01月21日 22:59"
# processed_date = process_date(date_str)
# print(processed_date)


# import datetime
#
#
# def process_date_string(date_string):
#     # 去除字符串中的非数字字符
#     date_number = ''.join(filter(str.isdigit, date_string))
#
#     # 将字符串转换为日期格式
#     try:
#         date = datetime.datetime.strptime(date_number, '%Y年%m月%d日 %H:%M')
#         return date
#     except ValueError:
#         return None
#
#
# # 示例日期字符串
# date_string = '2020年01月21日 22:59'
# # date_string = date_string.replace('年', '').replace('月', '').replace('日', '')
# # 处理日期字符串
# processed_date = process_date_string(date_string)
# if processed_date:
#     print(processed_date)
# else:
#     print('日期格式不正确')


# from datetime import datetime
# # 原始字符串
# s = '202001212259'
# # 格式化字符串
# format = '%Y%m%d%H%M'
# # 使用strptime函数将字符串转换为datetime对象
# dt = datetime.strptime(s, format)
# print(dt)

# from datetime import datetime, timedelta
# # 获取当前时间
# now = datetime.now()
# # 加一天
# one_day = timedelta(days=1)
# new_date = now + one_day
# print(new_date)

#
# from datetime import datetime
#
# comments = [
#     {"text": "comment 1", "date": "2021-01-01"},
#     {"text": "comment 2", "date": "2021-01-01"},
#     {"text": "comment 3", "date": "2021-01-02"},
#     {"text": "comment 4", "date": "2021-01-02"},
#     {"text": "comment 5", "date": "2021-01-02"}
# ]
# date_counts = {}
# for comment in comments:
#     date_str = comment["date"]
#     date_obj = datetime.strptime(date_str, "%Y-%m-%d").date()
#     if date_obj in date_counts:
#         date_counts[date_obj] += 1
#     else:
#         date_counts[date_obj] = 1
# print(date_counts)


import pandas as pd

data = {
  '2020-01-21': 231,
  '2020-01-20': 56
}
df = pd.DataFrame(list(data.items()), columns=['Date', 'Value'])
df['Date'] = pd.to_datetime(df['Date']) # 将Date列转换为日期格式
df.to_excel('data.xlsx', index=False)

